﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace HA.ModFlow.Domain.FileLayer
{
    public abstract  class Package
    {
        protected FileType _fileType;

        #region 辅助参数

        //计数器
        protected int counter;
        //辅助字符串
        protected string helpString = "";

        #endregion





        /// <summary>
        /// 返回文件类型字符串
        /// </summary>
        public string FileTypeString
        {
            get {
                

                return _fileType.ToString();
            
            }
            
        }

        uint _nunit;


        /// <summary>
        /// 文件单元，不可以是99
        /// </summary>
        public uint Nunit
        {
            get { return _nunit; }
            set { _nunit = value; }
        }


        string _fname;

        public string Fname
        {
            get { return _fname; }
            set { _fname = value; }
        }


        public abstract void WriteFile(string path);

        #region 辅助方法

        protected bool GetArrayString(double[,] array, ref string str)
        {
            str = "";
            if (array.Length <= 0)
            {
                return false;
            }
            else
            {
                for (int i = 0; i <= array.GetUpperBound(0); i++)
                {
                    for (int j = 0; j <= array.GetUpperBound(1); j++)
                    {
                        str += array[i, j].ToString("0.00000E+00   ")+" ";
                    }
                    str += "\r\n";
                }
            }
            return true;
        }

        protected bool GetArrayString(int[,] array, ref string str)
        {
            str = "";
            if (array.Length <= 0)
            {
                return false;
            }
            else
            {
                for (int i = 0; i <= array.GetUpperBound(0); i++)
                {
                    for (int j = 0; j <= array.GetUpperBound(1); j++)
                    {
                        str += string.Format("{0,10}", array[i, j])+"  ";
                    }
                    str += "\r\n";
                }
            }
            return true;
        }

        protected bool GetArrayString(double[] array, ref string str)
        {
            str = "";
            if (array.Length <= 0)
            {
                return false;
            }
            else
            {
                for (int i = 0; i < array.Length; i++)
                {
                    str += array[i].ToString("0.00000E+00   ")+" ";
                }
                str += "\r\n";
            }
            return true;
        }

        protected bool IsConstant(double[,] array)
        {
            double compare;
            if (array.Length <= 0)
            {
                return false;
            }
            else
            {
                compare = array[0, 0];
                for (int i = 0; i <= array.GetUpperBound(0); i++)
                {
                    for (int j = 0; j <= array.GetUpperBound(1); j++)
                    {
                        if (array[i, j] != compare)
                        {
                            return false;
                        }
                    }
                }
            }

            return true;
        }
        protected bool IsConstant(int [] array)
        {
            int  compare;
            if (array.Length <= 0)
            {
                return false;
            }
            else
            {
                compare = array[0];
                for (int i = 0; i < array.Length; i++)
                {
                    if (array[i] != compare)
                    {
                        return false;
                    }
                }
            }
            return true;
        }

        protected bool GetArrayString(int [] array, ref string str)
        {
            str = "";
            if (array.Length <= 0)
            {
                return false;
            }
            else
            {
                for (int i = 0; i < array.Length; i++)
                {
                    str +=string .Format ("{0,10}", array[i])+" ";
                }
                str += "\r\n";
            }
            return true;
        }
      

        protected bool IsConstant(int[,] array)
        {
            int compare;
            if (array.Length <= 0)
            {
                return false;
            }
            else
            {
                compare = array[0, 0];
                for (int i = 0; i <= array.GetUpperBound(0); i++)
                {
                    for (int j = 0; j <= array.GetUpperBound(1); j++)
                    {
                        if (array[i, j] != compare)
                        {
                            return false;
                        }
                    }
                }

            }
            return true;
        }

        protected bool IsConstant(double[] array)
        {
            double compare;
            if (array.Length <= 0)
            {
                return false;
            }
            else
            {
                compare = array[0];
                for (int i = 0; i < array.Length; i++)
                {
                    if (array[i] != compare)
                    {
                        return false;
                    }
                }
            }
            return true;
        }

        #endregion
    }
}
